package com.fyz.aaronfjava.common.handler;

import com.fyz.aaronfjava.common.constant.HttpConstant;
import com.fyz.aaronfjava.util.Jwt;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @Author：AaronF
 * @Date：2024/1/31 15:54
 * @description 身份验证拦截器
 */
@Component
public class AuthHandler implements HandlerInterceptor {

    /**
     * 身份验证
     */
    @Override
    public boolean preHandle(HttpServletRequest req, HttpServletResponse resp, Object handler){
        String token = req.getHeader(HttpConstant.TOKEN_HEADER);
        // 校验token有效期
        return Jwt.validate(token);
    }

}
